﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace TanmiaGrp.GeneralLedger.WinApp
{
    public class NullToVisibilityConverter : MarkupExtension, IValueConverter
    {
        private static NullToVisibilityConverter converter;

        public NullToVisibilityConverter()
        {
        }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string not = System.Convert.ToString(parameter);

            if (not.Equals("NOT"))
                return value == null ? Visibility.Visible : Visibility.Hidden;
            else
                return value == null ? Visibility.Hidden : Visibility.Visible;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (converter == null)
                converter = new NullToVisibilityConverter();

            return converter;
        }
    }
}
